package com.andy.qhb.controller.game;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.andy.qhb.base.RespVO;
import com.andy.qhb.controller.GameController;
import com.andy.qhb.dao.DaoUtils;
import com.andy.qhb.entity.UsrGroups;
import com.andy.qhb.game.GameUser;
import com.andy.qhb.game.Global;
import com.andy.qhb.game.Room;
import com.andy.qhb.utils.JsonUtils;

@Controller
@RequestMapping(value="game/api")
public class Api113Controller extends GameController{
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	/**
	 * 新建群
	 * @param session
	 * @param data
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="113")
	public RespVO action(HttpSession session,String data) throws Exception{
		GameUser user = getUser(session);
		Map<String, Object> reqData = JsonUtils.json2Map(data);
		
		Integer type = MapUtils.getInteger(reqData, "type");
		Integer coin = MapUtils.getInteger(reqData, "coin");
		Integer num = MapUtils.getInteger(reqData, "num");
		String multiple = MapUtils.getString(reqData, "multiple");
		
		UsrGroups group = new UsrGroups();
		group.setName((type == 1?"扫雷-":"禁抢-")+num+"包");
		group.setCid(user.getId());
		group.setGuids(user.getId()+",");
		group.setRemark(type+"-"+coin+"-"+num+"-"+multiple);
		
		DaoUtils.insert(group);
		user.addGroup(group);
		Global.addGroup(group );
		
//		SendUtil.send113(myWebSocket, group);
		Room room = Global.getRoom(group.getId().intValue());
		return RespVO.createSuccessJsonResonse(room);
	}
	
	
}